/*
 * @Description:
 * @Author: py
 * @Date: 2024-08-07
 */
import type { OptionsRow, OptionsType } from 'plus-pro-components'

export function useDicts() {
    const newsType = {
        0: '公告通知0',
        1: '公告通知1',
        2: '公告通知2',
        3: '公告通知3',
        4: '公告通知4',
        5: '公告通知5',
        6: '公告通知6',
    }

    const propertyType = {
        0: '住宅0',
        1: '住宅1',
        2: '住宅2',
        3: '住宅3',
        4: '住宅4',
        5: '住宅5',
        6: '住宅6',
    }

    const dicts = {
        newsType,
        propertyType,
    }

    const getDictLabel = (mapKey: string, dicKey: number | string) => {
        if (mapKey in dicts) {
            return dicts[mapKey][dicKey]
        }
        else {
            return ''
        }
    }

    const getDictOptions: (mapKey: string) => OptionsRow[] = (mapKey: string) => {
        if (mapKey in dicts) {
            const targetMap = dicts[mapKey]
            const dictOptions = Object.entries(targetMap).map(([key, val]) => ({
                label: val,
                value: key,
            }))
            return dictOptions as OptionsRow[]
        }
        else {
            return []
        }
    }

    return { getDictLabel, getDictOptions }
}
